﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;

namespace WX_Service
{
    /// <summary>
    /// wx_service 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class wx_service : System.Web.Services.WebService
    {

        [WebMethod]
        public void SetUserInfo(string openId,string NickName,string formId)
        {
            string sql = "select 1 from TB_UserInfo where openId=@openId";
            SqlParameter ps = new SqlParameter("@openId", SqlDbType.NVarChar, 50) { Value=openId};
            int rowCount = DBAccess.ExecuteDataTable(sql, ps).Rows.Count;
            if (rowCount > 0)
            {
                sql = "update TB_UserInfo set formId=@formId where openId=@openId";
                SqlParameter[] ps2 = { 
                                         new SqlParameter("@formId", SqlDbType.NVarChar, 50) { Value = formId } ,
                                         new SqlParameter("@openId", SqlDbType.NVarChar, 50) { Value = openId }
                                     };
                DBAccess.ExecuteNonQuery(sql,ps2);
            }
            else
            {
                sql = "insert into TB_UserInfo(openId,NickName,formId) values(@openId,@NickName,@formId)";
                SqlParameter[] ps3 = { 
                                         new SqlParameter("@openId", SqlDbType.NVarChar, 50) { Value = openId } ,
                                         new SqlParameter("@NickName", SqlDbType.NVarChar, 50) { Value = NickName },
                                         new SqlParameter("@formId", SqlDbType.NVarChar, 50) { Value = formId }
                                     };
                DBAccess.ExecuteNonQuery(sql, ps3);
            }
        }
    }
}
